export default {
	// 开启命名空间
	namespaced: true,

	// state 数据
	state: {
		myInfo: JSON.parse(uni.getStorageSync('myInfo') || '{}'),
		InfoList: JSON.parse(uni.getStorageSync('InfoList') || '[]'),
	},

	// 方法
	mutations: {
		CreateMyInfo(state, data) {
			state.myInfo = data;
			uni.setStorageSync('myInfo', JSON.stringify(state.myInfo));
			this.commit('info/AddInfoList');
		},
		AddInfoList(state) {
			const existingIndex = state.InfoList.findIndex(item => item.id === state.myInfo.id);
			if (existingIndex > -1) {
				state.InfoList[existingIndex] = state.myInfo;
			} else {
				state.InfoList.push(state.myInfo);
			}
			
			uni.setStorageSync('InfoList', JSON.stringify(state.InfoList));
		},
		deleteInfoList(state, index) {
			state.InfoList.splice(index, 1);
			uni.setStorageSync('InfoList', JSON.stringify(state.InfoList));
		}
	},

	// 数据包装器
	getters: {},
}